import { Router } from 'vue-router'

/**
 * 路由白名单
 */
const whitePathList = ['/login', '/401', '/404', '/512']

/**
 * 路由守卫
 */
export const setupRouteGuard = (router: Router) => {
  router.beforeEach((to, from, next) => {
    if (to.path !== '/login' && !localStorage.getItem('token')) {
      next({ path: '/login' })
    } else if (whitePathList.includes(to.path)) {
      next()
    } else {
      next()
    }
  })
}
